package com.zjs.jsp.fdservice;

import com.currencyboot.RocketMqCurrencyBoot;
import com.currencyboot.service.rocketmq.MqProducer;
import com.currencyboot.service.rocketmq.messagelistener.Interface.MessageListenerConsumerInterface;
import com.currencyboot.service.rocketmq.messagelistener.Interface.MqExceedCountInterface;
import com.currencyboot.service.rocketmq.spring.SpringContextUtils;
import com.zjs.jsp.fdservice.implement.AdditionalDataJspTask;
import com.zjs.jsp.fdservice.implement.PathPlanning;
import com.zjs.jsp.fdservice.messagelistener.ConsumableMessageListenerConsumer;
import com.zjs.jsp.fdservice.messagelistener.MqExceedCount;
import com.zjs.jsp.fdservice.service.SendJspTask;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.io.IOException;


@EnableFeignClients
@EnableScheduling
@EnableCaching
@EnableDiscoveryClient
@SpringBootApplication
public class FdServiceApplication
{
    public static void main(String[] args) {

        final ApplicationContext applicationContext =
                SpringApplication.run(new Object[]{RocketMqCurrencyBoot.class, FdServiceApplication.class}, args);
        SpringContextUtils.setApplicationContext(applicationContext);
    }

    /**
     * 构建 发送MQ 类   Bean
     */
    @Bean
    MqProducer mqProducer() {
        return new MqProducer();
    }

    /**
     * 容错异常处理
     */
    @Bean
    MqExceedCountInterface mqExceedCount() {
        return new MqExceedCount();
    }

    /**
     * 内销
     */
    @Bean
    MessageListenerConsumerInterface consumableMessageListenerConsumer() {
        return new ConsumableMessageListenerConsumer();
    }


    /**
     * 路径规划类  处理类
     */
    @Bean
    PathPlanning pathPlanning() {
        return new PathPlanning();
    }

    /**
     * 合包数据源与逻辑 处理类
     */
    @Bean
    AdditionalDataJspTask additionalData() {
        return new AdditionalDataJspTask();
    }


    /**
     * 下发任务包处理类
     */
    @Bean
    SendJspTask sendJspTask() {
        return new SendJspTask();
    }


    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() throws IOException {
        return Redisson.create(
                Config.fromYAML(new ClassPathResource("redisson.yml").getInputStream())
        );
    }



}
